package checkers3d.presentation;

/**
 * A visible GUI component (which inherits from GUIPictureBox) that exists as a
 * bitmapped image. A text label will be associated with each instance of this
 * object. The button can have either on or off states. This class must be used
 * with GUIButtonRadioGroup. Do not add it directly to a GUIContainer.
 *
 * @author Ruben Acuna
 */
public class GUIButtonRadio extends GUIPictureBox
{
    //TODO: the render resources should probably be cached elsewhere.
    /**
     * RenderResource for button in on state.
     */
    RenderResourceBitmap iconOn = new RenderResourceBitmap("gui_button_radio_on.png");

    /**
     * RenderResource for button in off state.
     */
    RenderResourceBitmap iconOff = new RenderResourceBitmap("gui_button_radio_off.png");

    /**
     * Button label text.
     */
    String text;

    /**
     * Class constructor that uses a pre-existing String for text data. The
     * button will default to an off state.
     *
     * @param text Button label text.
     * @see GUIPictureBox
     */
    public GUIButtonRadio(String text)
    {
        //RA: we can't pass iconOff because this is a call to super, so we must
        //    call setOff() afterward to set the render resource.
        super(null);
        setOff();

        this.text = text;
    }

    /**
     * Turns on this GUIButtonRadio.
     */
    public void setOn()
    {
        setRenderResource(iconOn);
    }

    /**
     * Turns off this GUIButtonRadio.
     */
    public void setOff()
    {
        setRenderResource(iconOff);
    }

    /**
     * Returns true if this GUIButtonRadio is currently on.
     *
     * @return GUIButtonRadio on/off state.
     */
    public boolean isOn()
    {
        if(getRenderResource() == iconOn)
            return true;
        else
            return false;
    }

    /**
     * Returns the text label display next to this button.
     *
     * @return Text associated with button.
     */
    public String getText()
    {
        return text;
    }

    /**
    * Returns a string representation of the GUIButtonRadio which contains
    * information about its parent GUIPictureBox.
    *
    * @return       A string representation of this GUIButtonRadio.
    */
    @Override
    public String toString()
    {
        String state = isOn() ? "On": "Off";

        return getClass().getName() + " -> " + text + " [" + super.toString() + "] " + state;
    }
}